//
//  SettingViewController.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/4/25.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "SettingViewController.h"
#import "LoginViewController.h"
#import "ContactForUsViewController.h"
#import "AboutUsViewController.h"
#import "UserInfoTableViewCell.h"
#define UserCellId @"cellid1"
@interface SettingViewController ()<UIAlertViewDelegate>
{
    NSArray *contentArray;
}
@end

@implementation SettingViewController

#pragma mark - Life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self resetNav];
    contentArray = @[@"",@"",@""];
    [self.dataArray addObjectsFromArray:@[@[@"联系我们",@"关于"],@[@"退出登录"]]];
}

#pragma mark - Property

#pragma mark - UI
- (void)resetNav{
    [self setTheBackBtn];
    self.myTitle.text = @"设置";
    [self.tableView registerClass:[UserInfoTableViewCell class] forCellReuseIdentifier:UserCellId];
}
#pragma mark - UI Response

#pragma mark - Data handle
- (void)setWebData{
    
}
#pragma mark - Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
    return 2;
    }else{
    return 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50*HeightRate;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==1) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"是否退出当前账号？" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
        
//        UIAlertController *alert  = [UIAlertController alertControllerWithTitle:@"是否退出当前账号?" message:nil preferredStyle:UIAlertControllerStyleAlert];
//        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//            [Userdefault setUser:nil];
//            [PublicMethod noTokenToLoginWithNav:self.navigationController];
//        }]];
//        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
//        dispatch_async(dispatch_get_main_queue(), ^{
//            [self presentViewController:alert animated:YES completion:nil];
//        });
    }else{
        if (indexPath.row == 0) {
            ContactForUsViewController *con = [[ContactForUsViewController alloc]init];
            [self.navigationController pushViewController:con animated:YES];
        }else{
            AboutUsViewController *con = [[AboutUsViewController alloc]init];
            [self.navigationController pushViewController:con animated:YES];
        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UserInfoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:UserCellId];
    cell.titleLab.text = self.dataArray[indexPath.section][indexPath.row];
    cell.img.image = [UIImage imageNamed:@"enter"];
    return  cell;
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex) {
        [Userdefault setUser:nil];
        [PublicMethod noTokenToLoginWithNav:self.navigationController];
       [[NSNotificationCenter defaultCenter]postNotificationName:@"out" object:nil];
    }
    
}


@end
